<template>
	<view class="container">
		<!--列表.开始-->
		<view class="group-box">
			<uni-swipe-action class="record-list">
				<!--循环.开始-->
				<uni-swipe-action-item v-for="(item,index) in listData" :key="index">
					<view class="list-box">
						<view class="left">
							<text :user-select="true" class="title">{{item.tradeNo}}</text>
							<text class="date">[{{item.paymentTitle}}] {{item.addTime}}</text>
						</view>
						<view class="right">
							<text class="text">￥{{item.amount}}</text>
							<navigator v-if="item.status===1" class="btn" :url="'../../payment/confirm?no='+item.tradeNo">去付款</navigator>
							<text v-else-if="item.status===2" class="btn gray">已完成</text>
							<text v-else class="btn gray">已取消</text>
							
						</view>
					</view>
					<template v-slot:right>
						<view v-if="item.status===0" @click="deleteItem(item.id)" class="list-btn">
							<text class="icon iconfont icon-delete"></text>
						</view>
						<view v-else class="list-btn gray">
							<text class="icon iconfont icon-delete"></text>
						</view>
					</template>
				</uni-swipe-action-item>
				<!--循环.结束-->
			</uni-swipe-action>
			<uni-load-more :status="loadingType" @clickLoadMore="loadData('add')"></uni-load-more>
		</view>
		<!--列表.结束-->
		
		<view class="foot-wrap">
			<view class="foot-box">
				<navigator url="add" class="btn-add">账户充值</navigator>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {}, //会员信息
				loadingType: "more", //加载状态
				totalCount: 0, //总数量
				totalPages: 0, //总页数
				pageSize: 10, //每页显示条数
				pageIndex: 1, //当前页码
				listData: [], //数据列表
			}
		},
		methods: {
			//初始化数据,带下滑刷新和上滑加载
			loadData(type='add', loading){
				let _this = this;
				//上滑加载更多
				if(type === 'add'){
					if(_this.loadingType === 'nomore'){
						return;
					}
					_this.loadingType = 'loading';
				}
				//下滑刷新
				else{
					_this.pageIndex=1;
					_this.listData=[];
					_this.loadingType="more";
				}
				//加载列表
				_this.$api.request({
					url: `/account/member/recharge?pageSize=${_this.pageSize}&pageIndex=${_this.pageIndex}`,
				}).then(res=>{
					let pageInfo = JSON.parse(res.header["x-pagination"]);
					_this.totalCount = pageInfo.totalCount;
					_this.totalPages = pageInfo.totalPages;
					let listData = res.data;
					//console.log(res.data)
					_this.listData = _this.listData.concat(listData);
				}).catch((err)=>{
					_this.loadingType="nomore";
					uni.stopPullDownRefresh();
				});
				
				//判断是否还有下一页
				if(_this.pageIndex >= _this.totalPages){
					_this.loadingType="nomore";
				}else{
					_this.pageIndex++;
					_this.loadingType="more";
				}
				//下滑隐藏动画及上滑事件
				if(type === 'refresh'){
					if(loading == 1){
						uni.hideLoading()
					}else{
						uni.stopPullDownRefresh();
					}
				}
			},
			//初始化数据
			async initData(){
				let _this = this;
				//正在加载
				uni.showLoading({
				    title: '加载中'
				});
				//获取会员信息
				await _this.$api.request({
					url: "/account/member",
				}).then((res) => {
					_this.model = res.data;
				});
				//加载数据列表
				await _this.loadData('add');
				//关闭加载
				uni.hideLoading();
			},
			//删除记录
			async deleteItem(id){
				let _this=this;
				await _this.$api.request({
					url: `/account/memberrecharge/${id}`,
					method: "delete",
					load: true
				}).then(res=>{
					this.loadData('refresh');
				});
			}
		},
		//页面初始化
		onLoad(options){
			this.initData();
		},
		//下滑刷新
		onPullDownRefresh(){
			this.loadData('refresh');
		},
		//上滑加载更多
		onReachBottom(){
			this.loadData('add');
		}
	}
</script>

<style lang="scss">
	.foot-wrap{
		height: 96rpx;
		.foot-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			padding: 0 24rpx;
			height: 100rpx ;
			.btn-add{
				display: block;
				padding: 0 48rpx;
				color: #fff;
				font-size: 30rpx;
				line-height: 76rpx;
				width: 100%;
				height: 76rpx;
				text-align: center;
				background: #ff5000;
				border-radius: 48rpx;
				box-shadow: 0 2rpx 8rpx rgba($color: #ff5000, $alpha: 0.2)
			}
		}
	}
</style>